elementobject.eventproperty = eventlistener;
<body> <button id='button'>Click Me!</button> <!-- There is no invocation of event listener here. --> <h id='demo'></h> <script> function clickme() { document.getElementById('demo').innerHTML = 'Hmmm'; } document.getElementById('button').onclick = clickme; </script> </body>
<head> <style> ... </style> <script> ... </script> </head> <body> ... </body>
<head> <script> // The W3C model function clickme() { document.getElementById('demo').innerHTML = 'Hmmm'; } document.getElementById('button').addEventListener('click', clickme); // NOT the invocation of an event listener /* Or the traditional model function clickme() { document.getElementById('demo').innerHTML = 'Hmmm'; } document.getElementById('button').onclick = clickme; // NOT the invocation of an event listener */ /* Or document.getElementById('button').onclick = function() { // Anonymouse function - a function that has no name document.getElementById('demo').innerHTML = 'Hmmm'; } */ </script> </head> <body> <button id='button'>Click Me!</button> <!-- There is no invocation of event listener here. --> <p id='demo'></p> </body>
document.getElementById('button').addEventListener(...);
should be executed after <body> is completed loaded.<head> <script> function clickme() { document.getElementById('demo').innerHTML = 'Hmmm'; } function start() { document.getElementById('button').addEventListener('click', clickme); // NOT the invocation of an event listener } window.addEventListener('load', start); // This event is triggered when the <body> is completely loaded. // The second argument is NOT the invocation of an event listener. /* OR window.addEventListener('???', ???() { document.getElementById('button').addEventListener('click', clickme); }); */ </script> </head> <body> <button id='button'>Click Me!</button> <!-- There is no invocation of event listener here. --> <p id='demo'></p> </body>
<head> <style> ... </style> </head> <body> ... </body> <script> ... </script>
document.getElementById('control').addEventListener('click', eh); function eh(eobj) { // eobj is an Event object. The browser invokes this function with the Event object. eobj.target.innerHTML = 'Hmmm'; // target: the element object on which this event is triggered. }
eventObj.key
eventObj.clientX, event.clientY
eventObj.target.id
write(), getElementById(), addEventListener()
elementobj.attributename, elementobj.getAttribute(name), elementobj.setAttribute(name, value)
elementobj.style.csspropertyname, elementobj.style.getProperty(name), elementobj.style.setProperty(name, value)
window.innerHeight, window.innerWidth
document, alert(), setInterval(), setTimeout()
load, resize
createElement(), createTextNode(), appendChild()
newlycreatedelementobj.id = 'newid'; newlycreatedelementobj.setAttribute('id', 'newid');
elementobj.childNodes